package com.topboya.officeuser.aop;

import org.apache.catalina.filters.RequestFilter;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @className ValidLoginAspect
 * @Author xiaxin
 * @Date 2020/12/25 19:34
 * @Version 1.0
 **/
@Component
@Aspect
public class ValidLoginAspect {

    public static final Logger logger = LoggerFactory.getLogger(ValidLoginAspect.class);

    @Pointcut("@annotation(com.topboya.officeuser.annotation.ValidLogin)")
    public void annotationPointcut(){

    }

    @Before("annotationPointcut()")
    public void beforePointcut(JoinPoint joinPoint) throws Exception {
        System.out.println("==========进入校验是否登录接口");
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        try {
            throw new Exception("抛出异常");
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Around("annotationPointcut()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        return joinPoint.proceed();
    }

    /**
     * 在切入点return内容之后切入内容（可以用来对处理返回值做一些加工处理）
     * @param joinPoint
     */
    @AfterReturning("annotationPointcut()")
    public void doAfterReturning(JoinPoint joinPoint) {
    }
}
